package com.yuanfeng.goods.controller;


import com.yuanfeng.commoms.annnotation.Log;
import com.yuanfeng.commoms.constant.CommonStatusEnum;
import com.yuanfeng.commoms.dto.base.DealerGoodsUserInfoDTO;
import com.yuanfeng.commoms.dto.goods.CommonShopStateDTO;
import com.yuanfeng.commoms.dto.oos.OssUploadUpdateParamDTO;
import com.yuanfeng.commoms.util.ResponseResult;
import com.yuanfeng.commoms.vo.goods.NoneGoodsQueryDTO;
import com.yuanfeng.goods.dto.*;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * @ClassName GoodsBaseController
 * @Description 商品表
 * @Author cyp
 * @Date 2023-05-25 09:16:26
 * @Version 1.0
 **/
@RestController
@RequestMapping("/goods/base")
public class GoodsBaseController extends BaseController {

    /**
     * 根据商品id修改收藏数
     *
     * @param goodId
     * @return
     */
    @GetMapping("/updateGoodsCollect")
    public ResponseResult updateGoodsCollect(@RequestParam("goodId") Integer goodId) {
        ResponseResult result = goodsBaseService.updateGoodsCollect(goodId);
        return result;
    }

    /**
     * 订单购物车中获取商品信息，及校验信息
     *
     * @param goodsId
     * @return
     */
    @GetMapping("/get/cart/getGoodsDetails")
    public ResponseResult getGoodsDetails(@RequestParam Integer goodsId) {
        ResponseResult goodsDetails = goodsBaseService.getGoodsDetails(goodsId);
        return goodsDetails;
    }

    /**
     * 查询出售中的商品规格列表
     *
     * @param param
     * @return
     */
    @PostMapping("/goods/list/query")
    public ResponseResult queryByGoodsBaseList(@RequestBody ManageCommonIdsDTO param) {
        ResponseResult result = goodsBaseService.queryByGoodsBaseList(param);
        return result;
    }

    /**
     * 查询出售中的商品规格列表 活动版
     *
     * @param param
     * @return
     */
    @PostMapping("/goods/list/query3")
    public ResponseResult queryByGoodsBaseList3(@RequestBody ManageCommonIdsDTO param) {
        ResponseResult result = goodsBaseService.queryByGoodsBaseList3(param);
        return result;
    }

    /**
     * 查询编辑秒杀商品的规格列表
     *
     * @param param
     * @return
     */
    @PostMapping("/querySeckillGoodsList")
    public ResponseResult querySeckillGoodsList(@RequestBody ManageCommonIdsDTO param) {
        ResponseResult result = goodsBaseService.querySeckillGoodsList(param);
        return result;
    }

    /**
     * 根据goodsid 直接修改库存和库存最大值
     * @param param
     * @return
     */
    @PostMapping("/goods/list/updateById")
    public ResponseResult queryGoodsBaseByCommonIdAndGoodsId(@RequestBody ManageGoodsBaseListResultDTO param) {
        ResponseResult result = goodsBaseService.updateGoodsBaseByCommonIdAndGoodsId(param);
        return result;
    }

    /**
     * 新增商品
     * @param param
     * @return
     */
    @Log("新增商品")
    @PostMapping("/newAddGoods")
    public ResponseResult newAddGoods(@RequestBody ManageGdsCommonPublishDTO param) {

        if (CollectionUtils.isEmpty(param.getGoodsImages())) {
            return ResponseResult.fail(CommonStatusEnum.FAIL.getCode(),"请上传商品主图");
        }
        if(null == param.getSpecParam() || param.getSpecParam().isEmpty()) {
            return ResponseResult.fail(CommonStatusEnum.FAIL.getCode(),"规格不能为空");
        }
        if(param.getSpecParam().size() > 3) {
            return ResponseResult.fail(CommonStatusEnum.FAIL.getCode(),"规格数量不能超过3个");
        }

        ResponseResult result = goodsBaseService.newAddGoods(param);
        return result;
    }

    /**
     * 更新商品
     *
     * @param param
     * @return
     */
    @PostMapping("/update")
    @Log("更新商品")
    public ResponseResult updateGoods(@RequestBody ManageGdsCommonUpdateDTO param) {

        if(null == param.getSpecParam() || param.getSpecParam().isEmpty()) {
            return ResponseResult.fail(CommonStatusEnum.FAIL.getCode(),"规格不能为空");
        }
        if(param.getSpecParam().size() > 3) {
            return ResponseResult.fail(CommonStatusEnum.FAIL.getCode(),"规格数量不能超过3个");
        }
        ResponseResult result = goodsBaseService.updateGoods(param);
        return result;
    }

    /**
     * 查看商品
     *
     * @param param
     * @return
     */
    @PostMapping("/query")
    public ResponseResult queryGoods(@RequestBody ManageCommonIdsDTO param) {
        ResponseResult result = goodsBaseService.queryGoods(param);
        return result;
    }

    /**
     * 校验商品是否是自己的
     * @param goodsUserInfo
     * @return
     */
    @PostMapping("/supplyChain/isMeGoods")
    public ResponseResult isMeGoods(@RequestBody DealerGoodsUserInfoDTO goodsUserInfo){
        ResponseResult meGoods = goodsBaseService.isMeGoods(goodsUserInfo);
        return meGoods;
    }
    /**
     * 查询所有商品 多个goodsID
     *
     * @param param
     * @return
     */
    @PostMapping("/all/goods/querygoods")
    public ResponseResult queryAllGoodsInfo(@RequestBody PlatFormAllGoodsDTO param) {
        ResponseResult result=goodsBaseService.queryAllGoodsInfo(param);
        return result;

    }

    /**
     *商品搜索导出
     * @param param
     * @param response
     * @return
     */
    @PostMapping("/goods/selectDetailsExp")
    public ResponseResult selectCommodityDetailsExp(@RequestBody GoodsDetailsDTO param, HttpServletResponse response){
        ResponseResult result=goodsBaseService.selectCommodityDetailsExp(param,response);
        return result;
    }

    /**
     * 查询商品规格等详情
     * @param param
     * @return
     */
    @PostMapping("/goods/selectDetails")
    public ResponseResult selectCommodityDetails(@RequestBody GoodsDetailsDTO param) throws IllegalAccessException {
        ResponseResult result=goodsBaseService.selectCommodityDetails(param);
        return result;
    }

    /*
     *查询红包下的商品列表
     */
    @PostMapping( "/selectGoodsDetailByRct")
    public ResponseResult selectGoodsDetailByRct(@RequestBody(required = false) Map<String, Object> paraMap) {
        ResponseResult result=goodsBaseService.selectGoodsDetailByRct(paraMap);
        return result;
    }


    /**
     * 更新sku商品 除shopId无其他条件
     *
     * @param map
     * @return
     */
    @PostMapping("/updateGoodsBase")
    public ResponseResult updateGoodsBaseByMap(@RequestBody Map<String, Object> map) {
        ResponseResult result = goodsBaseService.updateGoodsBaseByMap(map);
        return result;
    }


    /**
     * 更新sku商品状态
     *
     * @param commonParam
     * @return
     */
    @PostMapping("/updateGoodsBaseState")
    public ResponseResult updateGoodsBaseState(@RequestBody CommonShopStateDTO commonParam) {
        ResponseResult result = goodsBaseService.updateGoodsBaseState(commonParam);
        return result;
    }

    /**
     * 平台删除 积分商品
     *
     * @param param
     * @return
     */
    @PostMapping("/deleteIntegralGoods")
    public ResponseResult deleteIntegralGoods(@RequestBody ManageCommonIdsDTO param) {
        ResponseResult result = goodsBaseService.deleteIntegralGoods(param);
        return result;
    }

    /**
     * 平台查询 积分商品列表
     *
     * @param param
     * @return
     */
    @PostMapping("/queryIntegralGoodsAll")
    public ResponseResult queryIntegralGoodsAll(@RequestBody Map<String, Object> param) {
        ResponseResult result = goodsBaseService.queryIntegralGoodsAll(param);
        return result;
    }

    /**
     * 查询商品信息
     * @param commonId
     * @return
     */
    @GetMapping("/get/cart/getGoodsCommonDetails")
    public ResponseResult getGoodsCommonDetails(@RequestParam Integer commonId) {
        ResponseResult result = goodsBaseService.getGoodsCommonDetails(commonId);
        return result;
    };


    /**
     * 查询出售中的商品规格列表
     *
     * @param param
     * @return
     */
    @PostMapping("/goods/list/query2")
    public ResponseResult queryByGoodsBaseList2(@RequestBody ManageCommonIdsDTO param) {
        ResponseResult result = goodsBaseService.queryByGoodsBaseList2(param);
        return result;
    }


    /**
     * 批量调价
     *
     * @param param
     * @return
     */
    @PostMapping("/price/batchUpdate")
    public ResponseResult batchUpdateGoodsPrice(@RequestBody Map<String,Object> param) {
        ResponseResult result = goodsBaseService.batchUpdateGoodsPrice(param);
        return result;
    }


    /**
     * 修改同步供应商商品的 价格
     */
    @PostMapping("/updateSupperGoodsPrice")
    public ResponseResult updateSupperGoodsPrice(@RequestBody UpdateSupperGoodsPriceDTO param) {
        ResponseResult result = goodsBaseService.updateSupperGoodsPrice(param);
        return result;
    }

    /**
     * 批量上架同步供应商商品
     */
    @PostMapping("/updateSupperGoodsStart")
    public ResponseResult updateSupperGoodsStart(@RequestBody Map<String,Object> param) {
        return goodsBaseService.updateSupperGoodsStart(param);
    }

    /**
     * 查询同步供应商商品 的价格
     */
    @PostMapping("/querySupperGoodsPrice")
    public ResponseResult querySupperGoodsPrice(@RequestBody Map<String,Object> param) {
        ResponseResult result = goodsBaseService.querySupperGoodsPrice(param);
        return result;
    }


    /**
     * 根据typeId查询商品发布相关信息
     *
     * @param param
     * @return
     */
    @PostMapping("/typeid/query")
    public ResponseResult queryByTypeId(@RequestBody ManageByTypeIdParamInfoDTO param) {
        ResponseResult result = goodsBaseService.queryByTypeId(param);
        return result;
    }


    /**
     * 上传图片到oss服务器
     * @param param
     * @return
     */
    @PostMapping("/OSS/insertOssPhotoPort")
    public ResponseResult insertOssPhotoPort(@RequestBody OssPhotoInsertDTO param) {
        ResponseResult result = goodsBaseService.insertOssPhotoPort(param);
        return result;
    }

    /**
     * 根据商品id查询详情
     *
     */
    @PostMapping("/goodsid/query")
    public ResponseResult queryGdsDetail(@RequestBody WapGoodsDetailQueryDTO param) {
        ResponseResult result = goodsBaseService.queryGdsDetail(param);
        return result;
    }

    /**
     * h5首页猜你喜欢
     *
     * @return
     */
    @PostMapping("/h5Userfoot/query")
    public ResponseResult queryFootPrintH5(@RequestBody GuessYouLikeQueryDTO param) {
        ResponseResult result = goodsBaseService.queryFootPrintH5(param);
        return result;
    }

    /**
     * 获取 移动端 商品分享页海报
     *
     * @param param
     * @return
     */
    @PostMapping("/h5/goods/getGoodsPoster")
    public ResponseResult getGoodsPoster(@RequestBody Map<String, Object> param) {
        ResponseResult result = goodsBaseService.getGoodsPoster(param);
        return result;
    }



    /**
     * 查询活动专区商品
     *
     * @param param
     * @return
     */
    @PostMapping("/goods/query")
    public ResponseResult queryNoneGoods(@RequestBody NoneGoodsQueryDTO param) throws IllegalAccessException {
        ResponseResult result=goodsBaseService.queryNoneGoods(param);
        return result;
    }


    /**
     * 上传图片或文档
     *
     * @param param
     * @return
     */
    @PostMapping("/oss/upload")
    public ResponseResult uploadToOss(@RequestBody OssUploadUpdateParamDTO param) {
        ResponseResult result=goodsBaseService.uploadToOss(param);
        return result;
    }
}

